﻿#include "../../libcat/include/cat-module.hpp"
#include "mode3_gamepad.hpp"

const char* get_name() {
	return u8"手柄模式";
}

const char* get_default_config_name() {
	return u8"data\\gamepad\\PS4手柄示例.json";
}

void* Init(cat_data_t* settings) {

	gamepad::GetInstance()->Init(settings->json);

	return settings;
}

void* Update(cat_data_t* settings) {

	gamepad::GetInstance()->Update(settings->json);

	return settings;
}

void* Release() {

	gamepad::GetInstance()->Release();
	
	return NULL;
};

void* Run(void* _window) {

	cat_window* cwindow = (cat_window*)_window;

	gamepad::GetInstance()->Draw(cwindow);

	return _window;
};
void* OnJoystickButtonPress(const cat_joystick_button_event* event, bool up) {
	gamepad::GetInstance()->OnJoyButtonPress(event,up);
	return NULL;
}


void* OnjoystickAxisMove(const cat_joystick_axis_move_event* event) {
	gamepad::GetInstance()->OnJoyAxisMove(event);
	return NULL;
}
void* OnKeyPress(const cat_key_event* event, bool key_up) {
	gamepad::GetInstance()->OnKeyPress(event, key_up);
	return NULL;
};
/*声明一个模块*/
CAT_DECLARE_MODULE()
bool cat_module_load() {
	cat_source_info gamepad{};
	gamepad.id = 3;
	gamepad.type = CAT_SOURCE_TYPE_MODE;
	gamepad.Init = Init;
	gamepad.Update = Update;
	gamepad.Release = Release;
	gamepad.Run = Run;
	gamepad.get_name = get_name;
	gamepad.get_default_config_name = get_default_config_name;
	gamepad.OnJoystickButtonPress = OnJoystickButtonPress;
	gamepad.OnjoystickAxisMove = OnjoystickAxisMove;
	gamepad.OnKeyPress = OnKeyPress;

	cat_register_source(&gamepad);
	return true;
}